#include <dbg.h>
#include <gtest/gtest.h>
using namespace std;

class Solution {
public:
    int findBottomLeftValue(TreeNode* root) {
        int res = 0;
        if (!root) {
            return res;
        }

        queue<TreeNode*> que;
        que.push(root);
        while (!que.empty()) {
            for (int i = 0; i < que.size(); ++i) {
                TreeNode* node = que.front();
                que.pop();
                if (i == 0) {
                    res = node->val;
                }
                if (node->right) {
                    que.push(node->right);
                }
                if (node->left) {
                    que.push(node->left);
                }
            }
        }

        return res;
    }
};

TEST(TEST1, findBottomLeftValue) {
    Solution s;

    TreeNode* root = new TreeNode(2, new TreeNode(1), new TreeNode(3));
    EXPECT_EQ(s.findBottomLeftValue(root), 1);
}

TEST(TEST2, findBottomLeftValue) {
    Solution s;

    TreeNode* root = new TreeNode(
        1,
        new TreeNode(2, new TreeNode(4), nullptr),
        new TreeNode(
            3, new TreeNode(5, new TreeNode(7), nullptr), new TreeNode(6)));
    EXPECT_EQ(s.findBottomLeftValue(root), 7);
}

int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}